//
//  AppDelegate+DB.m
//  iPlan
//
//  Created by 侯伟 on 2021/9/27.
//

#import "AppDelegate+DB.h"
#import <Realm/Realm.h>

@implementation AppDelegate (DB)

#pragma mark -- <迁移数据库>
- (void)migrationRealmAction{

    //1.获取默认配置
    RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
    //2.叠加版本号（要比上一次版本号高）
    int newVersion = 2;
    config.schemaVersion = newVersion;
    //3.迁移步骤
    [config setMigrationBlock:^(RLMMigration * _Nonnull migration, uint64_t oldSchemaVersion) {
            if (oldSchemaVersion < newVersion) {
                NSLog(@"--需要迁移--oldSchemaVersion:%llu migration:%@",oldSchemaVersion,migration);
            }
    }];
    //4.让配置生效
    [RLMRealmConfiguration setDefaultConfiguration:config];
    
    //5.需要立即迁移
    [RLMRealm defaultRealm];
}

@end
